export default {
  data() {
    return {
      listInterface: '',
      firstGetData: false,
      reconstruction: false,
      tableLoading: false,
      pagination: {
        total: 0,
        current: 1,
        pageSize: 100
      }
    }
  },
  computed: {
    params() {
      return this.$refs.filterForm.getParms()
    }
  },
  methods: {
    submit(val) {
      this.pagination.current = 1
      this.getData(val)
    },

    reset() {

    },

    paginationChange(val) {
      this.pagination.current = val?.current || this.pagination.current
      this.pagination.pageSize = val?.pageSize || this.pagination.pageSize
      // this.$refs.filterForm.submitFormFilter()
      this.getData()
    },

    getData(val) {
      if (!val) {
        val = this.params
      }

      let params = {
        num: this.pagination.current,
        size: this.pagination.pageSize,
        ...val
      }

      if (val && val.date) {
        params.startTime = val.date[0]
        params.endTime = val.date[1]

        delete params.date
      }

      params = this.parameterReconstruction(params)

      this.tableLoading = true

      this.listInterface(params).then(res => {
        this.tableLoading = false
        if (res.code === 200) {
          if (this.reconstruction) {
            this.dataReconstruction(res)
          } else {
            this.tableData = res.data
          }
        } else {
          this.$message.error(res.message)
        }
      })
    },

    parameterReconstruction(params) {
      return params
    },

    dataReconstruction(res) {
      this.tableLeft = res.data.expenseVOList
      this.tableData = res.data.pageInfo.list
      this.pagination.total = res.data.pageInfo.total
    },

    formatMoney(data) {
      if (!data && data !== 0) return data
      const temp = parseFloat(data)
      return temp.toFixed(2)
    }
  }
}
